import type {ExtractPropTypes, PropType} from 'vue'
import {buildProps, type DevMethods} from "@/utils";


export const devSelectProps = buildProps({
  // 接口地址
  api: {
    type: Function as PropType<(params?: any) => Promise<any>>,
    default: () => {
      return () => Promise.resolve({}); // 默认返回空 Promise，防止报错
    }
  },
  // 是否使用接口
  useApi: {
    type: Boolean,
    default: false
  },
  // 接口请求携带的参数
  apiParams: {
    type: Object as PropType<any>,
    default: () => {
      return {};
    }
  },
  options: {
    type: Array as PropType<Record<string, any>[]>,
    default: () => []
  },
  // 是否在vue3 onMounted生命周期中调用
  onMounted: {
    type: Boolean,
    default: true
  },
  // 是否在vue3 onActivated生命周期中调用
  onActivated: {
    type: Boolean,
    default: false
  },
  devSelectFieldsFn:{
    type: Function as PropType<DevMethods['devSelectFieldsFn']>,
  },
  optionValueKey: {
    type: String,
    default: 'value'
  },
  optionLabelKey: {
    type: String,
    default: 'label'
  },
  optionDisabledKey: {
    type: String,
    default: 'disabled'
  },
  useModelObj: {
    type: Boolean,
    default: false
  },
  objMapper: {
    type: [Object, Boolean] as PropType<Record<string, any> | boolean>,
    default: false  // false 表示直接绑定整个对象，Object 则为映射配置
  }
} as const)
export type DevSelectProps = ExtractPropTypes<typeof devSelectProps>
